package darknet.core.spec.net;

import darknet.application.Application;

import java.io.IOException;
import java.util.List;

/**
 * Describe a manager able to manage network connection.
 * 
 * @author yoyo
 */
public interface NetworkManager {
    
    /**
     * Get all supported protocol.
     * 
     * @return
     */
    List<Protocol> getProtocols();
    
    /**
     * Get an application, or null if protocol is not found.
     * 
     * @param protocol The protocol used by the application.
     * @return
     */
    Application getApplication(Protocol protocol);

    /**
     * Send a message.
     * 
     * @param message	The message to send.
     */
    Response send(Message message) throws IOException;
    
    /**
     * Receive a message.
     * 
     * @param message
     */
    void receive(StreamableMessage message) throws IOException;
    
    /**
     * Update node infos.
     * 
     * @param node
     */
    void update(Node node);

    /**
     * Synchronise the network manager context.
     */
    void synchronise() throws IOException;
    
    /**
     * Get a node via his name, or null if the node don't already exist.
     * 
     * @param nodeName The node name.
     * @return
     */
    Node getNode(String nodeName);

    /**
     * @return all online nodes.
     */
    List<Node> getOnlineNodes();
    
    /**
     * Get my node.
     * @return
     */
    Node myNode();
}
